package com.yang.SpingBoot.controller;

import com.yang.SpingBoot.model.WeiBo;
import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;

@RestController
public class TestController {

    private Logger logger = LoggerFactory.getLogger(TestController.class);

    @GetMapping("/login")
    public String login(){

        logger.info("开始登陆...");


        return "hello world";
    }


    public static void main(String[] args) throws Exception {

        File dir = new File("D://data");

        File[] files = dir.listFiles();
        for (File file : files) {
            if (file.isFile()){
                String html = FileUtils.readFileToString(file);

                Document document = Jsoup.parse(html);
                for (Element weiboElment : document.select(".card-wrap")) {
                    String weiboContent = weiboElment.select(".txt").text();
                    Elements ul = weiboElment.select(".card-act").select("ul>li");
                    String shoucang = ul.get(0).text().replaceAll("[^0-9]","");
                    String zhuanfa = ul.get(1).text().replaceAll("[^0-9]","");
                    String pinglun = ul.get(2).text().replaceAll("[^0-9]","");
                    String dianzan = ul.get(3).text().replaceAll("[^0-9]","");


                    WeiBo weiBo = new WeiBo();

                    weiBo.setContent(weiboContent);
                    weiBo.setShoucang(shoucang);
                    weiBo.setDianzan(dianzan);
                    weiBo.setPinglun(pinglun);
                    weiBo.setZhuanfa(zhuanfa);
                }



            }
        }

    }

}
